<?php
// Do not access this file directly
if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) { die (__('Please do not load this page directly. Thanks!')); }
		
// Password Protection
if (!empty($post->post_password)) { if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {
?>
		
		<p class="center"><?php _e('This post is password protected. Enter the password to view comments.'); ?></p>
		<?php return; } } ?>
		
		<?php if (($comments) or ('open' == $post->comment_status)) : ?>
		
		<div class="comment-section">
			<h4 id="comments" class="section-title"><?php comments_number('No Responses', 'One Response', '% Responses' );?></h4>
			<?php /* Seperate comments and pings */
					if ( $post->comment_count > 0 ) {
						$countComments = 0;
						$countPings    = 0;
						
						$comment_list = array();
						$ping_list    = array();
		
						foreach ($comments as $comment) {
							if ( 'comment' == get_comment_type() ) {
								$comment_list[++$countComments] = $comment;
							} else {
								$ping_list[++$countPings] = $comment;
							}
						}
					}
			?>
				
			<hr />
			<?php /* Check for comments */ if ( $countComments > 0 ) { ?>
			<ol id="commentlist">
				<?php foreach ($comment_list as $comment_index => $comment) { ?>
				<li id="comment-<?php comment_ID(); ?>">
				<?php if (function_exists('gravatar')) { ?> <a href="http://www.gravatar.com/" title="What is this?"><img src="<?php gravatar("X", 32, get_bloginfo('template_url')."/images/default_gravatar.png"); ?>" class="gravatar" alt="Gravatar Icon" /></a>
				<?php } ?>
					<div class="comment-header"><a href="#comment-<?php comment_ID(); ?>" class="counter" title="Permanent Link to this Comment"><?php echo $comment_index; ?></a><?php comment_author_link() ?> <?php if($comment->comment_author_email == "guesswhomosquito@gmail.com") echo "<small>(the author)</small>" ?></div>
					<div class="comment-content"><?php comment_text() ?></div>
					<div class="comment-footer">
						<span class="metacmt">Comment on <a href="#comment-<?php comment_ID() ?>" title="Permalink to Comment"> <?php comment_date('M jS, Y'); ?> at <?php comment_time(); ?></a></span>&nbsp;&nbsp;<?php if ( $user_ID ) { edit_comment_link('Edit','<span class="metaedit">','</span>'); } ?>
					</div>
					
					<?php if ('0' == $comment->comment_approved) { ?>
					<p class="alert"><strong>您的评论请等待审核。</strong></p>
					<?php } ?>
				</li>
				<?php } /* End foreach comment */ ?>
				
			</ol>
			<!-- END #commentlist -->
			<?php } /* end comment check */ ?>
			
			<?php /* Check for Pings */ if ( $countPings > 0 ) { ?>
			<ol id="pinglist">
			
				<?php foreach ($ping_list as $ping_index => $comment) { ?>
				<li id="comment-<?php comment_ID(); ?>">
					<div class="comment-header"><a href="#comment-<?php comment_ID() ?>" title="Permanent Link to this Comment" class="counter"><?php echo $ping_index; ?></a><?php comment_author_link() ?></div>
					<div class="comment-content"><?php comment_text() ?></div>
					<div class="comment-footer"><span class="metacmt"><?php comment_type(); ?> on <a href="#comment-<?php comment_ID() ?>" title="Permalink to Comment"><?php comment_date('M jS, Y'); ?> at <?php comment_time(); ?></a></span>&nbsp;&nbsp;<?php if ( $user_ID ) { edit_comment_link('Edit','<span class="metaedit">','</span>'); } ?></div>
				</li>
				<?php } /* end foreach ping */ ?>
				
			</ol>
			<!-- END #pinglist -->
			<?php } /* end ping check */ ?>
			
			<?php /* Comments open, but empty */ if ( ($post->comment_count < 1) and ('open' == $post->comment_status) ) { ?>
			<ol id="commentlist">
			    <li id="nocomment">
				<?php if (function_exists('gravatar')) { ?> <a href="http://www.gravatar.com/" title="What is this?"><img src="<?php bloginfo('template_url'); ?>/images/avatar.gif" class="gravatar" alt="Gravatar Icon" /></a>
				<?php } ?>
					<div class="comment-header"><?php the_author_link(); ?></div>
					<div class="comment-content">本文还没有评论，何不发表第一个评论呢。</div>
					<div class="comment-footer">
						<span class="metacmt">Comment on <?php the_date('M jS, Y'); ?> at <?php the_time(); ?></span>
					</div>
				</li>	
			</ol>
			<?php } ?> 
			<?php /* Comments closed */ if (('open' != $post->comment_status) and is_single()) { ?>
			<div>评论已经关闭！</div>
			<?php } ?>
		
		</div>
		<!-- END .comments 1 -->
		<?php endif; ?>
		
		<?php /* Reply Form */ if ('open' == $post->comment_status) { ?>
		<div class="comment-section">
			<h4 class="section-title">Leave a Reply</h4>
			<?php if (get_option('comment_registration') and !$user_ID) { ?>
			<p><?php printf('You must <a href="%s">login</a> to post a comment.', get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink()); ?></p>
			<?php } else { ?>
			
			<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
			
				<?php if ( $user_ID ) { ?>
				<div class="metalinks"><?php printf('Logged in as %s.', '<a href="' . get_option('siteurl') . '/wp-admin/profile.php">' . $user_identity . '</a>') ?> <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout &raquo;</a></div>
				<?php } elseif ($comment_author != "") { ?>
				<p><?php printf('Welcome back <strong>%s</strong>.', $comment_author) ?></p>
				<?php } ?> <?php if ( !$user_ID ) { ?>
				
				<div id="authorinfo">
					<p>
						<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
						<label for="author">Name<?php if ($req) __('(required)'); ?></label>
					</p>
					<p>
						<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
						<label for="email">Mail <small>(will not be published)</small><?php if ($req) __('(required)'); ?></label>
					</p>
					<p>
						<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
						<label for="url">Website</label>
					</p>
				</div>
				
				<?php } ?>
				<p>
					<textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea>
				</p>
				
				<p>
					<input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
					<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
					<?php do_action('comment_form', $post->ID); ?>
				</p>
				
			</form>
			
			<?php } // If registration required and not logged in ?>
		
		</div>
		<!-- END .comments #2 -->
		
		<?php } ?>